package com.ruoyi.project.manhua.climb.service.impl;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.stream.Collectors;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.manhua.name.domain.MhName;
import com.ruoyi.project.manhua.name.service.IMhNameService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.manhua.climb.mapper.MhClimbMapper;
import com.ruoyi.project.manhua.climb.domain.MhClimb;
import com.ruoyi.project.manhua.climb.service.IMhClimbService;
import com.ruoyi.common.utils.text.Convert;

/**
 * 漫画爬虫Service业务层处理
 *
 * @author yuan
 * @date 2021-02-10
 */
@Service
public class MhClimbServiceImpl implements IMhClimbService
{
    @Autowired
    private MhClimbMapper mhClimbMapper;

    @Autowired
    private IMhNameService mhNameService;

    /**
     * 查询漫画爬虫
     *
     * @param id 漫画爬虫ID
     * @return 漫画爬虫
     */
    @Override
    public MhClimb selectMhClimbById(Long id)
    {
        return mhClimbMapper.selectMhClimbById(id);
    }

    /**
     * 查询漫画爬虫列表
     *
     * @param mhClimb 漫画爬虫
     * @return 漫画爬虫
     */
    @Override
    public List<MhClimb> selectMhClimbList(MhClimb mhClimb)
    {
        return mhClimbMapper.selectMhClimbList(mhClimb);
    }

    /**
     * 新增漫画爬虫
     *
     * @param mhClimb 漫画爬虫
     * @return 结果
     */
    @Override
    public int insertMhClimb(MhClimb mhClimb)
    {
        mhClimb.setCreateTime(DateUtils.getNowDate());
        return mhClimbMapper.insertMhClimb(mhClimb);
    }

    /**
     * 修改漫画爬虫
     *
     * @param mhClimb 漫画爬虫
     * @return 结果
     */
    @Override
    public int updateMhClimb(MhClimb mhClimb)
    {
        mhClimb.setUpdateTime(DateUtils.getNowDate());
        return mhClimbMapper.updateMhClimb(mhClimb);
    }

    /**
     * 删除漫画爬虫对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteMhClimbByIds(String ids)
    {
        return mhClimbMapper.deleteMhClimbByIds(Convert.toStrArray(ids));
    }

    /**
     * 删除漫画爬虫信息
     *
     * @param id 漫画爬虫ID
     * @return 结果
     */
    @Override
    public int deleteMhClimbById(Long id)
    {
        return mhClimbMapper.deleteMhClimbById(id);
    }

    /**
     * 查询 漫画所有数据 id与 name
     * @return
     */
    @Override
    public LinkedHashMap<Long, String> mapMhNames() {
        List<MhName> redisListAll = mhNameService.getRedisListAll();
        /*漫画全部数据*/
        return redisListAll.stream().collect(Collectors.toMap(
                (id) -> id.getId(),
                (name) -> name.getName(),
                (e1, e2) -> e1,
                LinkedHashMap::new
        ));
    }

}
